<?php

class Social_Controller_Browse_Linkedin_Oauth2callback
{

	function execute($request)
	{
		$adapter = Nuo::getObject('social/adapter/linkedin');

		$clientApi = $adapter -> getClientApi();

		$requestToken = $_SESSION['oauth']['linkedin']['request'];

		$oauthToken = $requestToken['oauth_token'];

		$oauthTokenSecret = $requestToken['oauth_token_secret'];

		$response = $clientApi -> retrieveTokenAccess($oauthToken, $oauthTokenSecret, $_GET['oauth_verifier']);

		if ($response['success'] === TRUE)
		{
			// the request went through without an error, gather user's
			// 'access' tokens
			$_SESSION['oauth']['linkedin']['access'] = $response['linkedin'];

			// redirect the user back to the demo page
			header('Location: ' . $_SERVER['PHP_SELF']);
		}
		else
		{
			// bad token access
			echo "Access token retrieval failed:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre><br /><br />LINKEDIN OBJ:<br /><br /><pre>" . print_r($clientApi, TRUE) . "</pre>";
		}
	}
}
